package co.edu.ucatolica.sislab.web.backinbeans;
import javax.faces.event.ActionEvent;

import co.edu.ucatolica.sislab.SISLABService;
import co.edu.ucatolica.sislab.persistence.DatabaseException;
import co.edu.ucatolica.sislab.users.domain.UserBean;
public class LoginBean {
	private static SISLABService service = SISLABService.getInstance();
	private String name;
    private String password;
    private String nextPage;
    public String getName (){
        return name;
    }
    public void setName (final String name){
        this.name = name;
    }
    public String getPassword (){
        return password;
    }
    public void setPassword (final String password){
        this.password = password;
    }
    public void action(ActionEvent event) {
        UserBean userBean = new UserBean();
        userBean.setLogin(name);
        userBean.setPassword(password);
        try {
			Long id = service.autenticateUser(userBean);
			if(id > 0){
				nextPage = "login";
			}else{
				nextPage = "";
			}
		} catch (DatabaseException e) {
			e.printStackTrace();
		}
        
    }
    public String nextPage(){
    	return nextPage;
    }
}
